/**
 * @file v4l2_capture.h
 * @brief V4L2 capture device handling header.
 *
 * This file defines the context and function prototypes for interacting
 * with a V4L2 video capture device, focusing on DMABUF-based buffer
 * management for zero-copy integration with DRM.
 */

#ifndef V4L2_CAPTURE_H
#define V4L2_CAPTURE_H

#include <linux/videodev2.h>
#include <stdbool.h>
#include "util.h"
#include "drm_device.h"

// Context structure to hold all V4L2 related information.
typedef struct v4l2_context
{
    int fd;
    char *device;

    // Format properties
    int width;
    int height;
    unsigned int in_fourcc;

    // Buffer properties
    unsigned int buffer_count;
    bool is_multiplanar;
    unsigned int num_planes;

    // Per-plane information for creating framebuffers in other subsystems (e.g., DRM)
    unsigned int *plane_pitches; // Stride for each plane
    unsigned int *plane_offsets; // Offset for each plane within the DMABUF

} v4l2_context_t;

// Initialization and Cleanup
int v4l2_init(v4l2_context_t *ctx);
void v4l2_cleanup(v4l2_context_t *ctx);

// Streaming Control
int v4l2_stream_on(v4l2_context_t *ctx, struct drm_buffer *drm_bufs);
int v4l2_stream_off(v4l2_context_t *ctx);

// Buffer Management
int v4l2_dequeue_buffer(v4l2_context_t *ctx, struct v4l2_buffer *buf);
int v4l2_queue_buffer(v4l2_context_t *ctx, struct v4l2_buffer *buf);

// Parameter Control (Example - can be extended)
int v4l2_set_control(v4l2_context_t *ctx, unsigned int id, int value);
int v4l2_set_fps(v4l2_context_t *ctx, int fps);

#endif // V4L2_CAPTURE_H
